package com.xiaolin.service;

import com.xiaolin.dao.MessageMapper;
import com.xiaolin.pojo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author XiaoLin
 * @date 2019/2/25 09:10
 */
@Service
public class MessageService {

    @Autowired
    private MessageMapper messageMapper;


    /**
     * 获取uid最近聊天信息
     *
     * @param userId
     * @return
     */
    public List<Message> findMessageByUId(String userId) {
        return messageMapper.findMessageByUId(userId);
    }

    /**
     * 新建聊天
     *
     * @param message
     */
    public void insert(Message message) {
        messageMapper.insert(message);
    }

    /**
     * 更新最后回复时间
     *
     * @param mid
     */
    public void upLastDate(Integer mid) {
        Message message = new Message();
        message.setMid(mid);
        message.setSendLastDate(new Date());
        messageMapper.updateByPrimaryKeySelective(message);
    }

    public Message findMessageByMid(Integer mid) {
        return messageMapper.findMessageByMid(mid);
    }


    public Message findMessageByUIdAndRid(String uid, String receiveUid) {
        return messageMapper.findMessageByUIdAndRid(uid, receiveUid);
    }
}
